<template>
    <div ref="rightPanel" :class="{show:show || showNotice}" class="rightPanel-container">
        <!--<div class="rightPanel-background" />-->
        <div class="rightPanel" style="padding: 15px">
            <div v-if="showBtn" class="handle-button" :style="{'top':buttonTop+'px','background-color':'#1890ff'}" @click="show=!show">
                <i :class="show?'el-icon-close':'el-icon-search'"/>
            </div>
            <div class="rightPanel-items">
                <slot/>
                <div v-if="showBtn" style="position: fixed; bottom: 20px; left: 117px;">
                    <el-button size="small" type="primary" @click="queryHandle">查询</el-button>
                    <el-button size="small" type="success" @click="resetHandle">重置</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {closetMatch} from '@/utils/closetMatch'
    export default {
        name: 'RightPanel',
        props: {
            clickNotClose: {
                default: false,
                type: Boolean
            },
            buttonTop: {
                default: 250,
                type: Number
            },
            showBtn:{
                default:true,
                type:Boolean
            },
            showNotice:{
                default:false,
                type:Boolean
            }
        },
        data() {
            return {
                show: false
            }
        },
        watch: {
            show(value) {
                if (value && !this.clickNotClose) {
                    this.addEventClick()
                }
            }
        },
        mounted() {
            this.insertToBody()
        },
        beforeDestroy() {
            const elx = this.$refs.rightPanel
            elx.remove()
        },
        methods: {
            addEventClick() {
                window.addEventListener('click', this.closeSidebar)
            },
            closeSidebar(evt) {
                closetMatch();
                const parent = evt.target.closest('.rightPanel')
                if (!parent) {
                    this.show = false
                    window.removeEventListener('click', this.closeSidebar)
                }
            },
            insertToBody() {
                const elx = this.$refs.rightPanel
                // const body = document.querySelector('body')
				const body = document.getElementsByClassName('main-cont')[0];
                body.insertBefore(elx, body.firstChild)
            },
            queryHandle() {
                this.$emit("search")
            },
            resetHandle() {
                this.$emit("reset")
            }
        }
    }
</script>

<style lang="scss">
    .showRightPanel {
        overflow: hidden;
        position: relative;
        width: calc(100% - 15px);
    }
    .rightPanel-items{
        height: 100%;
        .scrollbar-wrapper {
            overflow-x: hidden !important;
        }
    }
</style>

<style lang="scss" scoped>
    .rightPanel-background {
        opacity: 0;
        transition: opacity .3s cubic-bezier(.7, .3, .1, 1);
        background: rgba(0, 0, 0, .2);
        width: 0;
        height: 0;
        top: 0;
        left: 0;
        position: fixed;
        z-index: -1;
    }

    .rightPanel {
        background: #fff;
        z-index: 600;
        position: fixed;
        height: 100vh;
        width: 100%;
        max-width: 360px;
        top: 0px;
        left: 0px;
        box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
        transition: all .25s cubic-bezier(.7, .3, .1, 1);
        transform: translate(100%);
        z-index: 500;
        left: auto;
        right: 0px;
    }

    .show {
        transition: all .3s cubic-bezier(.7, .3, .1, 1);
    .rightPanel {
        transform: translate(0);
    }

    }

    .handle-button {
        position: absolute;
        left: -48px;
        border-radius: 6px 0 0 6px !important;
        width: 48px;
        height: 48px;
        pointer-events: auto;
        z-index: 0;
        cursor: pointer;
        pointer-events: auto;
        font-size: 24px;
        text-align: center;
        color: #fff;
        line-height: 48px;

    i {
        font-size: 24px;
        line-height: 48px;
    }

    }
</style>
